//
//  M_Comment.m
//  suRead
//
//  Created by 龚浩植 on 15/11/16.
//  Copyright © 2015年 bao. All rights reserved.
//

#import "M_Comment.h"

@implementation M_Comment

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
             @"f_article_id": @"article_id",
             @"f_comment_id": @"comment_id",
             @"f_content": @"content",
             @"f_create_time": @"create_time",
             @"f_from_cover": @"from_cover",
             @"f_from_id": @"from_id",
             @"f_from_name":@"from_name",
             @"f_pid":@"pid",
             @"f_small_cover":@"small_cover",
             @"f_status":@"status",
             @"f_title":@"title",
             @"f_to_cover": @"to_cover",
             @"f_to_id":@"to_id",
             @"f_to_name":@"to_name",
             @"f_type":@"type",
             @"f_children":@"children"
            };
}

+ (NSValueTransformer *)f_article_idJSONTransformer {

    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        return [NSString stringWithFormat:@"%@",value_];
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
}

+ (NSValueTransformer *)f_comment_idJSONTransformer {

    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        return [NSString stringWithFormat:@"%@",value_];
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
}

+ (NSValueTransformer *)f_from_idJSONTransformer {

    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        return [NSString stringWithFormat:@"%@",value_];
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
}

+ (NSValueTransformer *)f_statusJSONTransformer {

    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        return [NSString stringWithFormat:@"%@",value_];
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
}

+ (NSValueTransformer *)f_to_idJSONTransformer {

    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        return [NSString stringWithFormat:@"%@",value_];
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
}


+ (NSValueTransformer *)f_pidJSONTransformer {

    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        return [NSString stringWithFormat:@"%@",value_];
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
}

+ (NSValueTransformer *)f_contentJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSString *value_, BOOL *success, NSError **error){
        
        BOOL iOS8OrLater = kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0;

        if (iOS8OrLater) {
            //去掉html标签
            if ([value_ containsString:@"</span>"]) {
                value_ = [value_ stringByReplacingOccurrencesOfString:@"<br>" withString:@""];
                return value_;
                
            }
            else {
                return value_;
            }
        }
        else
        {
            NSRange range = [value_ rangeOfString:@"</span>"];
            if (range.location == NSNotFound) {
                return value_;
            }
            else {
                value_ = [value_ stringByReplacingOccurrencesOfString:@"<br>" withString:@""];
                return value_;
            }
        }
    }];
    
}
//
//+ (NSValueTransformer *)f_creat_atJSONTransformer {
//
//    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
//
//        if (!value_) {
//            return @" ";
//        }
//
//        double deltaSeconds = fabs([[NSDate date] timeIntervalSince1970] - value_.doubleValue); // 获取总共秒数
//        double deltaMinutes = deltaSeconds / 60.0f;
//
//        NSString *dateContent;
//        if (deltaSeconds < 5) {
//            dateContent = @"刚刚";
//        } else if (deltaSeconds < 120) {
//            dateContent = @"1分钟前";
//        } else if (deltaMinutes < 60) {
//            dateContent = [NSString stringWithFormat:@"%i分钟前", (int)deltaMinutes];
//        } else if (deltaMinutes < 120) {
//            dateContent = @"1小时前";
//        } else if (deltaMinutes < (24 * 60)) {
//            dateContent = [NSString stringWithFormat:@"%i小时前", (int)floor(deltaMinutes / 60)];
//        } else if (deltaMinutes < (24 * 60 * 2)) {
//            dateContent = @"昨天";
//        } else if (deltaMinutes < (24 * 60 * 7)) {
//            dateContent = [NSString stringWithFormat:@"%d天前", (int)floor(deltaMinutes/(60 * 24))];
//        } else if (deltaMinutes < (24 * 60 * 14)) {
//            dateContent = @"上周";
//        } else if (deltaMinutes < (24 * 60 * 31)) {
//            dateContent = [NSString stringWithFormat:@"%d周前", (int)floor(deltaMinutes/(60 * 24 * 7))];
//        } else if (deltaMinutes < (24 * 60 * 61)) {
//            dateContent = @"上个月";
//        } else if (deltaMinutes < (24 * 60 * 365.25)) {
//            dateContent = [NSString stringWithFormat:@"%d月前", (int)floor(deltaMinutes/(60 * 24 * 30))];
//        } else if (deltaMinutes < (24 * 60 * 731)) {
//            dateContent = @"去年";
//        } else {
//            dateContent = [NSString stringWithFormat:@"%i年前", (int)floor(deltaMinutes/(60 * 24 * 731))];
//        }
//
//        return dateContent;
//
//    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
//        return id_;
//    }];
//
//}

@end
